package com.sttg.csp.common.action;

import java.util.List;
import java.util.Map;
import com.opensymphony.xwork2.ActionContext;
import com.sttg.csp.common.exception.BizException;
import com.sttg.csp.common.util.paged.PagedList;

/**
 * Defined paged action. it extend BaseAction class.
 * 
 */
public abstract class PagedAction extends BaseAction {

	protected PagedList pagedRecords = new PagedList();
	
	public PagedAction() {
		super();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.sttg.nscg.common.action.BaseAction#getRows()
	 */
	@Override
	public List<?> getRows() {
		if (pagedRecords == null || pagedRecords.getTotalNum() == -1) {
			return this.rows;
		}
		return pagedRecords.getList();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.sttg.nscg.common.action.BaseAction#getTotal()
	 */
	public Integer getTotalNum() {
		if (pagedRecords == null || pagedRecords.getTotalNum() == -1) {
			return this.rows.size();
		}
		return pagedRecords.getTotalNum();
	}
	
	public Integer getTotalPage() {
		if (pagedRecords == null || pagedRecords.getTotalNum() == -1) {
			return 1;
		}
		return pagedRecords.getTotalPage();
	}
	
	public void setPageNum(int pageNum) {
		pagedRecords.setPageNum(pageNum);
	}
	
	public Integer getPageNum() {
		return pagedRecords.getPageNum();
	}
	
	public void setPageSize(int pageSize) {
		pagedRecords.setPageSize(pageSize);
	}
	
	public Integer getPageSize() {
		return pagedRecords.getPageSize();
	}
}
